#ps1

  param(
    [string]$puppetmaster = (throw "-puppetmaster is required.")
  )

  $puppet_source = "https://code.google.com/p/puppet-mssqlcluster/"
  $MsiUrl = "https://downloads.puppetlabs.com/windows/puppet-latest.msi"

  $currentPrincipal = New-Object Security.Principal.WindowsPrincipal([Security.Principal.WindowsIdentity]::GetCurrent())
  if (! ($currentPrincipal.IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator))) {
    Write-Host -ForegroundColor Red "You must run this script as an administrator."
    Exit 1
  }


  # Use Amazon tools to set hostname to internal ip address
  if (Test-Path  ("C:\Program Files\Amazon\Ec2ConfigService\Settings\Config.xml"))
  {
    $EC2SettingsFile="C:\Program Files\Amazon\Ec2ConfigService\Settings\Config.xml"
    $xml = [xml](get-content $EC2SettingsFile)
    $xmlElement = $xml.get_DocumentElement()
    $xmlElementToModify = $xmlElement.Plugins

    foreach ($element in $xmlElementToModify.Plugin)
    {
        if ($element.name -eq "Ec2SetComputerName")
        {
            $element.State="Enabled"
        }
    }
    $xml.Save($EC2SettingsFile)
  }

  # Install puppet - msiexec will download from the url
  $install_args = @("/qn", "/norestart","/i", $MsiUrl, "PUPPET_MASTER_SERVER=$puppetmaster")
  Write-Host "Installing Puppet. Running msiexec.exe $install_args"
  $process = Start-Process -FilePath msiexec.exe -ArgumentList $install_args -Wait -PassThru
  if ($process.ExitCode -ne 0) {
    Write-Host "Puppet installer failed."
    Exit 1
  }
  Write-Host "Puppet successfully installed."
  Start-Sleep -s 30
  Restart-Service puppet
